const express = require("express");
const app = express();

app.use(require('cors')()); //跨域
app.use(express.json());  //使用res.body
app.use('/admin/api/upload', express.static('upload')); //静态文件夹
app.use('/', express.static(__dirname + '/web')); //web端
require('./plugins/mongodb.js')(app)
require('./router/admin')(app)
require('./router/cars')(app)
require('./router/noteMode')(app)
require('./router/logData')(app)
require('./router/excels')(app)
require('./router/APP')(app)
require('./middle/tools')(app)
app.set('token', 'qazxsw') //设置token的钥匙


const Users = require('./models/User');
Users.findOne({ 'username': 'admin' }).then((e)=>{
    console.log("管理员信息", e)
    if(!e){
        Users.create({username:"admin",password:"123456",power:"admin"})
    }
})

//错误函数处理
app.use(async (err, req, res, next) => {
    console.log(err)
    res.status(err.statusCode || 500).send({
        message: err.message
    })
})
app.listen(3002, () => {
    console.log('开启了哟')
}) 